home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / PKTSTAT.ASM < prev    next >
Assembly Source File  |  1992-01-23  |  5KB  |  258 lines

  1. version    equ    1
  2.  
  3. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet statistics version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. int_pkt    macro
  37.     pushf
  38.     cli
  39.     call    their_isr
  40.     endm
  41.  
  42. their_isr    dd    ?
  43. packet_int_no    db    60h,0,0,0
  44. packet_int_end    db    7fh,0,0,0
  45.  
  46. handle        dw    ?
  47.  
  48. bogus_type    db    0,0        ;totally bogus type code.
  49.  
  50. signature    db    'PKT DRVR',0
  51. signature_len    equ    $-signature
  52. usage_msg    db    "usage: pktstat <packet_int_no> [packet_int_no_end]",'$'
  53.  
  54. stat_names    db    "    pkt_in    pkt_out    byt_in    byt_out    err_in    err_out    pk_drop",CR,LF,'$'
  55. printed_names    db    0        ;haven't printed the names yet.
  56.  
  57. statistics_list    label    dword
  58. packets_in    dw    ?,?
  59. packets_out    dw    ?,?
  60. bytes_in    dw    ?,?
  61. bytes_out    dw    ?,?
  62. errors_in    dw    ?,?
  63. errors_out    dw    ?,?
  64. packets_dropped    dw    ?,?        ;dropped due to no type handler.
  65. statistics_count    equ    $ - statistics_list
  66.  
  67. check_packet_no:
  68.     or    word ptr [di+2],0
  69.     jne    usage_error
  70.     cmp    word ptr [di],60h
  71.     jb    usage_error
  72.     cmp    word ptr [di],7fh
  73.     ja    usage_error
  74.     ret
  75.  
  76.  
  77. usage_error:
  78.     mov    dx,offset usage_msg
  79. error:
  80.     mov    ah,9
  81.     int    21h
  82.     int    20h
  83.  
  84. start_1:
  85.     cld
  86.  
  87.     mov    dx,offset copyleft_msg
  88.     mov    ah,9
  89.     int    21h
  90.  
  91.     mov    si,offset phd_dioa+1
  92.  
  93.     mov    di,offset packet_int_no
  94.     call    get_number
  95.     jc    start_2            ;if they entered a number, change the default.
  96.     mov    word ptr packet_int_end+0,cx
  97.     mov    word ptr packet_int_end+2,bx
  98. start_2:
  99.     call    check_packet_no
  100.  
  101.     mov    di,offset packet_int_end
  102.     call    get_number
  103.  
  104.     call    check_packet_no
  105.  
  106.     call    skip_blanks
  107.     cmp    al,CR
  108.     jne    usage_error
  109.  
  110.     mov    al,packet_int_no    ;make sure they're in the right order.
  111.     cmp    al,packet_int_end
  112.     ja    usage_error
  113.  
  114. chk_loop:
  115.     call    chk_int
  116.     mov    al,packet_int_no
  117.     cmp    al,packet_int_end
  118.     jz    all_done
  119.     inc    packet_int_no        ; increment
  120.     jmp    chk_loop
  121. all_done:
  122.     mov    al,0
  123.     mov    ah,04ch
  124.     int    21h            ; exit with errorlevel 0
  125.  
  126. chk_int:
  127. ;check packet_int_no for a packet driver.  If there's one there, print
  128. ;the statistics and return nc.  If not, return cy.
  129.     mov    ah,35h            ;get their packet interrupt.
  130.     mov    al,packet_int_no
  131.     int    21h
  132.     mov    their_isr.offs,bx
  133.     mov    their_isr.segm,es
  134.  
  135.     lea    di,3[bx]
  136.     mov    si,offset signature
  137.     mov    cx,signature_len
  138.     repe    cmpsb
  139.     je    have_signature
  140.     stc
  141.     ret
  142. have_signature:
  143.  
  144.     push    ds
  145.     mov    ax,1ffh            ;driver_info
  146.     int_pkt
  147.     pop    ds
  148.     call    fatal_error
  149.  
  150.     mov    ah,2            ;access_type
  151.     mov    al,ch            ;their class from driver_info().
  152.     mov    bx,dx            ;their type from driver_info().
  153.     mov    dl,cl            ;their number from driver_info().
  154.     mov    cx,2            ;use a type length of 2.
  155.     mov    si,offset bogus_type
  156.     push    cs            ;es:di -> our receiver.
  157.     pop    es
  158.     mov    di,offset our_recv
  159.     int_pkt
  160.     call    fatal_error
  161.     mov    handle,ax
  162.  
  163.     mov    ah,24            ;get the statistics
  164.     mov    bx,handle
  165.     int_pkt
  166.     jc    bad
  167.     assume    ds:nothing
  168. ;ds:si now points to the statistics list.
  169.     mov    cx,statistics_count/2
  170.     mov    ax,cs
  171.     mov    es,ax
  172.     mov    di,offset statistics_list
  173.     rep    movsw
  174.     mov    ds,ax            ;restore ds to cs.
  175.  
  176.     cmp    printed_names,0        ;have we printed the names yet?
  177.     jne    did_print_names
  178.  
  179.     inc    printed_names
  180.     mov    dx,offset stat_names
  181.     mov    ah,9
  182.     int    21h
  183. did_print_names:
  184.  
  185.     mov    al,packet_int_no    ;print the packet interrupt number.
  186.     call    byteout
  187.     mov    al,'I'-40h        ;tab over.
  188.     call    chrout
  189.  
  190.     mov    bx,offset statistics_list
  191.     mov    cx,statistics_count/4
  192. print_stats:
  193.     mov    ax,[bx]
  194.     mov    dx,[bx+2]
  195.     push    bx
  196.     push    cx
  197.     call    decout
  198.     pop    cx
  199.     pop    bx
  200.     add    bx,4
  201.     mov    al,'I'-40h        ;tab over.
  202.     call    chrout
  203.     loop    print_stats
  204.  
  205.     mov    dx,offset crlf_msg
  206.     mov    ah,9
  207.     int    21h
  208.  
  209.     mov    ah,3            ;release_type
  210.     mov    bx,handle
  211.     int_pkt
  212.     call    fatal_error
  213.  
  214.     clc
  215.     ret
  216.  
  217.  
  218. bad:
  219.     push    cs
  220.     pop    ds
  221.     call    print_error
  222.  
  223.     mov    ah,3            ;release_type
  224.     mov    bx,handle
  225.     int_pkt
  226.     call    fatal_error
  227.  
  228.     int    20h
  229.  
  230.  
  231. our_recv:
  232.     or    ax,ax            ;first or second call?
  233.     jne    our_recv_1        ;second -- we ignore the packet
  234.     push    cs
  235.     pop    es
  236.     mov    di,offset our_buffer
  237. our_recv_1:
  238.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  239.  
  240.  
  241.     include    printea.asm
  242.  
  243.     assume    ds:code
  244.  
  245.     include    pkterr.asm
  246.     include    getnum.asm
  247.     include    skipblk.asm
  248.     include    getdig.asm
  249.     include    decout.asm
  250.     include    digout.asm
  251.     include    chrout.asm
  252.  
  253. our_buffer    label    byte
  254.  
  255. code    ends
  256.  
  257.     end    start
  258.